package com.yonyou.cyxdms.sysAuth.service.controller.manage.authorization;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yonyou.cyx.framework.controller.base.BaseController;
import com.yonyou.cyxdms.sysAuth.service.dto.authorization.AuthorizationDTO;
import com.yonyou.cyxdms.sysAuth.service.service.authorization.AuthorizationService;
import com.yonyou.cyxdms.sysAuth.service.vo.authorization.AuthorizationVO;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author     ：quankk
 * @date       ：2019/7/9 17:59
 * @description：授权管理
 */
@Api(value = "授权管理Controller", tags = {"授权管理Controller"})
@RestController
@RequestMapping("/basedata/authorization")
public class AuthorizationController extends BaseController {

    // 定义日志接口
    private static final Logger logger = LoggerFactory.getLogger(AuthorizationController.class);

    @Autowired
    private AuthorizationService authorizationService;

    /**
     * @author     ：quankk
     * @date       ：2019/7/18 16:40
     * @description：加载授权主界面
     */
    @RequestMapping(method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ApiOperation(value = "加载授权主界面")
    @ApiImplicitParams({@ApiImplicitParam(value = "用户id", name = "userId", required = true, dataType = "string", paramType = "header")})
    public IPage<AuthorizationVO> queryAuthorization(@ApiParam(name = "pageNum", value = "当前页") @RequestParam("pageNum") Long current,
                                                     @ApiParam(name = "limit", value = "分页大小") @RequestParam("limit") Long size,
                                                     @RequestParam Map<String, String> param) {
        Page<AuthorizationVO> page = new Page(current, size);
        return authorizationService.queryAuthorization(page, param);
    }

    /**
     * @author     ：quankk
     * @date       ：2019/7/18 18:21
     * @description：授权信息获取
     */
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    @ApiOperation(value = "授权信息获取")
    public List<Map> getRoleById(@PathVariable(value = "id") Integer id) {
        return authorizationService.getRoleById(id);
    }

    /**
     * @author     ：quankk
     * @date       ：2019/7/18 18:30
     * @description：vue停用
     */
    @RequestMapping(value = "/vue/{id}", method = RequestMethod.DELETE)
    @ApiOperation(value = "vue停用")
    @ResponseStatus(HttpStatus.CREATED)
    public void vuePosition(@PathVariable(value = "id") Integer id) {
        authorizationService.vuePosition(id);
    }

    /**
     * @author     ：quankk
     * @date       ：2019/7/18 18:30
     * @description：新增授权
     */
    @RequestMapping(method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ApiOperation(value = "新增授权")
    @ResponseStatus(HttpStatus.CREATED)
    @ApiImplicitParams({@ApiImplicitParam(value = "用户id", name = "userId", required = true, dataType = "string", paramType = "header")})
    public void addAuthorization(@RequestBody AuthorizationDTO atdto) {
        authorizationService.addAuthorization(atdto);
    }

}
